using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;

public class EventUpTrigger : MonoBehaviour,
    IPointerUpHandler
{
    private UnityAction<PointerEventData> onPointerUpCallback;

    /// <summary>
    /// Adds a callback for the Pointer Up event.
    /// </summary>
    public static void AddPointerUp(GameObject gameObject, UnityAction<PointerEventData> callback)
    {
        var trigger = gameObject.GetComponent<EventUpTrigger>() ?? gameObject.AddComponent<EventUpTrigger>();
        trigger.onPointerUpCallback += callback;
    }


    public void OnPointerUp(PointerEventData eventData)
    {
        onPointerUpCallback?.Invoke(eventData);
    }
}
